package com.topsoft.email.interceptor;
import java.util.Iterator;

import org.hibernate.EmptyInterceptor;
import org.springframework.stereotype.Component;

/**
 * hibernate拦截器
 * @author guokaige
 *
 */
@Component
public class CacheIntercepter extends EmptyInterceptor{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

//	@Override
//	public void onDelete(Object entity, Serializable id, Object[] state,
//			String[] propertyNames, Type[] types) {
//		System.out.println("delete..............");
//		super.onDelete(entity, id, state, propertyNames, types);
//	}
//
//	@Override
//	public boolean onFlushDirty(Object entity, Serializable id,
//			Object[] currentState, Object[] previousState,
//			String[] propertyNames, Type[] types) {
//		System.out.println("flushDirty..............");
//		return super.onFlushDirty(entity, id, currentState, previousState,
//				propertyNames, types);
//	}
//
//	@Override
//	public boolean onSave(Object entity, Serializable id, Object[] state,
//			String[] propertyNames, Type[] types) {
//		System.out.println("save..............");
//		return super.onSave(entity, id, state, propertyNames, types);
//	}
//
//	@Override
//	public void onCollectionRecreate(Object collection, Serializable key)
//			throws CallbackException {
//		System.out.println("recreate..............");
//		super.onCollectionRecreate(collection, key);
//	}
//
//	@Override
//	public void onCollectionRemove(Object collection, Serializable key)
//			throws CallbackException {
//		System.out.println("remove..............");
//		super.onCollectionRemove(collection, key);
//	}
//
//	@Override
//	public void onCollectionUpdate(Object collection, Serializable key)
//			throws CallbackException {
//		System.out.println("collectionUpdate..............");
//		super.onCollectionUpdate(collection, key);
//	}
//
//	@Override
//	public boolean onLoad(Object entity, Serializable id, Object[] state,
//			String[] propertyNames, Type[] types) {
//		System.out.println("load..............");
//		return super.onLoad(entity, id, state, propertyNames, types);
//	}
//
//	@Override
//	public void postFlush(Iterator entities) {
//		System.out.println("flush..............");
//		if(entities.hasNext()){
//			System.out.println("-----------------------------"+entities.next().toString());
//		}
//		super.postFlush(entities);
//	}

	
	/**
	 * sql语句拦截
	 */
	@Override
	public String onPrepareStatement(String sql) {
		System.out.println("statement.............."+sql+"..........................");
		return super.onPrepareStatement(sql);
	}

	
	/**
	 * sql参数拦截
	 */
	@Override
	public void preFlush(Iterator entities) {
		if(entities.hasNext()){
			System.out.println("-----------------------------"+entities.next().toString());
		}
		super.preFlush(entities);
	}

}
